import { IsString, IsNotEmpty, MaxLength, IsOptional } from "class-validator";
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { QueryDto } from "/@/common/dto/query.dto";

export class AddGoodsDto {
  @ApiProperty({ description: "商品名称" })
  @MaxLength(50, { message: "name长度不超过50" })
  @IsString({ message: "不是有效的name" })
  @IsNotEmpty({ message: "name不能为空" })
  readonly name: string;

  @ApiProperty({ description: "商品重量" })
  readonly weight: number;

  @ApiProperty({ description: "商品价格" })
  price: number;

  @ApiProperty({ description: "商品库存" })
  stock: number;

  @IsOptional()
  @ApiPropertyOptional({ description: "商品推荐指数" })
  readonly recommend: number;

  @ApiProperty({ description: "商品分类" })
  goods_types: Array<any>;

  @IsOptional()
  @ApiPropertyOptional({ description: "商品标签" })
  @IsString({ message: "不是有效的label" })
  readonly label: string;

  @IsOptional()
  @ApiPropertyOptional({ description: "商品简介" })
  @IsString({ message: "不是有效的brief" })
  readonly brief: string;

  @ApiProperty({ description: "商品图片" })
  readonly urls: string;

  @IsOptional()
  @ApiPropertyOptional({ description: "商品详情" })
  @IsString({ message: "不是有效的details" })
  readonly details: string;

  @IsOptional()
  @ApiPropertyOptional({ description: "商品状态" })
  @IsString({ message: "status必须为字符串" })
  @IsNotEmpty({ message: "status不能为空" })
  status: string;

  @IsOptional()
  @ApiPropertyOptional({ description: "备注" })
  @IsString()
  readonly des: string;
}

export class DelGoodsDto {}
export class EditGoodsDto extends AddGoodsDto {
  @ApiProperty({ description: "商品id" })
  readonly id: number;
}
export class GetGoodsDto extends QueryDto {
  @IsOptional()
  @ApiPropertyOptional({ description: "商品名称" })
  @MaxLength(50, { message: "name长度不超过50" })
  @IsString({ message: "不是有效的name" })
  readonly name: string;

  @IsOptional()
  @ApiPropertyOptional({ description: "商品id" })
  readonly id: number;

  @IsOptional()
  @ApiPropertyOptional({
    description: "商品状态 1 生效 2 下架 3 逻辑缺货，具体库存在各自规格",
  })
  @IsString({ message: "status必须为字符串" })
  readonly status: string;
}

export class GetGoodsByTypeDto extends QueryDto {
  @ApiProperty({ description: "商品类型id" })
  readonly type_id: number | string;
}
